using System;
using System.ComponentModel;
using System.Web;
using com.paypal.sdk.profiles;

namespace InfoStuffStore.Common
{
    /// <summary>
    /// Summary description for Constants.
    /// </summary>
    public class SetProfile
    {

        /// <summary>
        /// Required designer variable.
        /// </summary
        public static readonly IAPIProfile DefaultProfile = CreateAPIProfile(Constants.API_USERNAME, Constants.API_PASSWORD, Constants.API_SIGNATURE, Constants.CERTIFICATE, Constants.PRIVATE_KEY_PASSWORD, "sandbox", Constants.SUBJECT, Constants.OAUTH_SIGNATURE, Constants.OAUTH_TOKEN, Constants.OAUTH_TIMESTAMP);

        public static IAPIProfile CreateAPIProfile(string apiUsername, string apiPassword, string signature, string CertificateFile_Cer, string PrivateKeyPassword_Cer, String stage, string subject, string oauth_Signature, string oauth_Token, string oauth_Timestamp)
        {
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
            profile.APIUsername = apiUsername;
            profile.APIPassword = apiPassword;
            profile.Environment = stage;
            profile.Subject = subject;
            profile.APISignature = signature;
            return profile;
        }

        public static void SetDefaultProfile()
        {
            SessionProfile = DefaultProfile;
        }

        public static string OrderCode
        {
            get
            {
                return HttpContext.Current.Session["OrderCode"].ToString();
            }
            set
            {
                HttpContext.Current.Session["OrderCode"] = value;
            }
        }

        public static IAPIProfile SessionProfile
        {
            get
            {
                return (IAPIProfile)HttpContext.Current.Session[Constants.PROFILE_KEY];
            }
            set
            {
                HttpContext.Current.Session[Constants.PROFILE_KEY] = value;
            }
        }

        public static void ClearSession()
        {
            SessionProfile = null;
            OrderCode = null;
        }
    }
}
